package cn.yunhe.dao;

import cn.yunhe.entity.Emp;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import javax.xml.ws.Action;
import java.util.List;
@Repository("dao")
public class EmpDao {
    @Resource
    private HibernateTemplate hibernateTemplate;

    public Emp findById(int id){
        return  hibernateTemplate.get(Emp.class,id);
    }
    public  void update(Emp emp){
        hibernateTemplate.update(emp);
    }
    public List<Emp> findAll(){
        List list = hibernateTemplate.find("from Emp");
        return  list;
    }
    public void add(Emp emp){
        hibernateTemplate.save(emp);
    }
    public  List<Emp> find(String keyword){
        List<Emp>  list = hibernateTemplate.find("from Emp where ename like ?","%"+keyword+"%");
        return  list;
    }
    public  void delete(Emp emp) {
        hibernateTemplate.delete(emp);
    }
    public  boolean login(String ename,String job){
        List emp = hibernateTemplate.find("from Emp where ename=? and job =?" ,ename,job);
        if(emp.size()>0){
            return true;
        }
        return  false;
    }



public HibernateTemplate getHibernateTemplate() {
        return hibernateTemplate;
    }

    public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
        this.hibernateTemplate = hibernateTemplate;
    }
}
